import React, { Component } from 'react'
// import {add, request} from '../store/actions'
import { add } from '../store/actions/count'
import { request } from '../store/actions/request'
import {connect} from 'react-redux'



class Comp2 extends Component {

  render() {
    console.log('this.props =========>', this.props);

    let {count, name, add, request, isLoading, err} = this.props
    return (
      <div>
        <h2>{count}</h2>
        <button onClick={add}>add</button>
        {
          isLoading ? <h2>正在请求...</h2> : 
          err.errCode ? <h2>请求失败{err.errMsg}</h2> :
          <h2>{name}</h2>
        }
        <button onClick={request}>request</button>
      </div>
    )
  }
}

function mapStateToProps(state) {

  return {
    count: state.count.count,
    name: state.request.name,
    isLoading: state.request.isLoading,
    err: state.request.err
  }
}

let mapDispatchToProps = {
  add,
  request
}

export default connect(mapStateToProps, mapDispatchToProps)(Comp2)
